package com.ugrow.ugrowcommunity;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.bumptech.glide.Glide;
import com.ugrow.ugrowcommunity.databinding.ActivityLaunchBinding;
import com.ugrow.ugrowcommunity.util.TimerTool;
import com.ugrow.ugrowcommunity.vm.home.InfoAdapter;
import com.ugrow.ugrowcommunity.vm.home.RootBean;

import java.util.List;

public class LaunchActivity extends AppCompatActivity {
    private ActivityLaunchBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityLaunchBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        initStatusBar();
        startLaunch();
    }

    private void initStatusBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
            window.setNavigationBarColor(Color.TRANSPARENT);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }

    private TimerTool timerTool;

    private void startLaunch() {
        binding.imageStart.setImageResource(R.mipmap.launch);
        binding.txtCountDown.setText("倒计时3秒");
        binding.txtCountDown.setVisibility(View.VISIBLE);
        binding.txtCountDown.setOnClickListener(v -> {
            timerTool.onFinish();
        });
        timerTool = new TimerTool(4000, 500);
        timerTool.setOnTimer(new TimerTool.OnTimer() {
            @Override
            public void OnTick(long millisUntilFinished) {
                String timeStr = "倒计时" + millisUntilFinished / 1000 + "秒";
                binding.txtCountDown.setText(timeStr);
            }

            @Override
            public void OnFinish() {
                startActivity(new Intent(LaunchActivity.this,LoginActivity.class));
                finish();
                timerTool.cancel();
            }
        });
        timerTool.start();
    }
}